package com.wxgy.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wxgy.entity.User;
import com.wxgy.service.IUserService;
import com.wxgy.service.UserService;
import com.wxgy.service.impl.UserServiceImpl;

/**
 * Servlet implementation class AddUserServlet
 */
@WebServlet("/AddUserServlet")
public class AddUserServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		String name = request.getParameter("uname");
		String password = request.getParameter("upwd");
		String sgrade = request.getParameter("ugrade");
		int grade=Integer.parseInt(sgrade);
		User user=new User();
		user.setUsername(name);
		user.setPasswd(password);
		user.setGrade(grade);
		IUserService us=new UserServiceImpl();
	    if(us.addUser(user)){
//	    	System.out.println("ok");
	    	response.sendRedirect("login.jsp");
	    }else{
	    	response.sendRedirect("register.jsp");
	    }
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		doGet(request, response);
	}

}
